package org.neuedu.servlet;

import org.neuedu.bean.Article;
import org.neuedu.bean.User;
import org.neuedu.service.ArticleService;
import org.neuedu.service.ArticleServiceImpl;
import org.neuedu.service.UserService;
import org.neuedu.service.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "UserSignInServlet",urlPatterns = "/forward/sign")
public class UserSignInServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        User fly_user = (User)session.getAttribute("fly_user");
        Integer d = fly_user.getId();
        UserService userService=new UserServiceImpl();
        userService.getUserById(Integer.valueOf(d));


        // service
        int i = userService.usersign(fly_user);
    if(i==1){
    fly_user.setKissNum(fly_user.getKissNum()+5);
    request.setAttribute("msg","签到成功");
    request.getRequestDispatcher("/forward/index").forward(request,response);
}else{
request.setAttribute("failsignmsg","今日已签到");
request.getRequestDispatcher("/forward/index").forward(request,response);
}



    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
